草庐IT

c++ - constexpr 和 ODR

全部标签

c++ - 如何使用 OpenSSL API 从其 PEM 格式字符串中读取 RSA 公钥?

我可以使用PEM_read_RSA_PUBKEY函数轻松读取PEM文件。但是,我有一个已内置到可执行文件中的公钥,我不想制作临时文件。阅读此示例/教程:http://hayageek.com/rsa-encryption-decryption-openssl-c/我想出了以下解决方案:#include#include#include#include#include#include#include#includeRSA*createRSA(constchar*key){RSA*rsa=nullptr;BIO*keybio;keybio=BIO_new_mem_buf(key,-1);//

c++ - 性能断言

我知道C支持使用assert()的函数式断言。有没有什么方法/库支持C/C++中的性能断言?有其他语言吗?大致如下:perf_assert_begin(ID1)....../*assertthetimetakenislessthan2000ms*/perf_assert_end(ID1,interval(ID1) 最佳答案 断言可以使用assert来完成来自或static_assert,它内置于语言中。那么,为什么不手动计时然后检查assert中的时差呢?声明?#include#include#ifndefNDEBUGautosta

c++ - LLVM 在运行时获取声明函数的参数值

我正在编写一个LLVMpass,它需要获取传递给声明函数的值并将其打印出来。请注意声明的函数在LLVMIR中被调用。我已经编写了一个模块传递来迭代程序中的所有指令。获取指令中被调用函数参数的片段如下:for(auto&B:F){for(auto&I:B){if(auto*InvokeI=dyn_cast(&I)){if(InvokeI->getCalledFunction()->getName().str()=="function_name"){errs()getOperand(0))getOperand(1))getOperand(2))但是,如果被调用函数的LLVMIR看起来像这样

c++ - 使用 constexpr C 字符串作为编译器错误消息

正如问题所暗示的,我想做的是templatestructbroken{templateconstexprbroken(Args&&...){//thesizeof...confusesthecompilerastoonlyemiterrorswheninstantiated//thisdoesnotwork,static_assertonlyacceptsstringliteralsstatic_assert(sizeof...(Args)我希望broken在实例化时发出编译器错误消息Err。但是,static_assert只接受一个字符串文字作为它的第二个参数。有什么方法可以根据co

c++ - 我什么时候不希望在 Microsoft Visual Studio 中启用 “Control Flow Guard”?

引自MSDN:ControlFlowGuard(CFG)isahighly-optimizedplatformsecurityfeaturethatwascreatedtocombatmemorycorruptionvulnerabilities.Byplacingtightrestrictionsonwhereanapplicationcanexecutecodefrom,itmakesitmuchharderforexploitstoexecutearbitrarycodethroughvulnerabilitiessuchasbufferoverflows.Westronglye

c++ - 构建 C/C++ 代码时的 Gradle 编译器输出

我正在Linux(gcc)和Windows(VS10)下使用gradle构建C/C++代码,就像在Buildingnativesoftwaredocumentation中描述的那样毕业典礼。构建过程很好,我可以启动我的应用程序。如果在构建过程中出现错误,您可以在控制台上看到类似警告和错误的编译器输出。此输出另外写入文件:build/tmp/"TaskName"/output.txt。问题是,如果构建运行没有错误,此输出不会显示在控制台上,但文件已写入。我正在寻找一种方法来在控制台上显示编译器输出,例如警告或错误,即使构建成功也是如此。可以使用更高的日志级别开始gradle构建:grad

c++ - 将 `hana::string` 转换为 `constexpr const char (&)[]`

我有一些旧代码使用了与str_const非常相似的东西描述here和here做一些constexpr字符串操作。str_const是ScottSchurr描述的文字类型,可以从字符串文字构造,因为它具有来自constchar(&)[]的模板构造函数.我现在也有一些使用boost::hana的新代码.我希望能够参加hana::string并创建一个str_const那是指它。最简单的方法是转换hana::string到constexprconstchar(&)[].(实际上,在这一点上这不是最简单的方法,最简单的方法肯定是在我的str_const实现中添加一个新的模板构造函数。但在这一点

c++ - 直接访问指针是否比通过结构访问指针更快?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭4年前。Improvethisquestion假设我有一个C程序,它遍历一个目录并将目录条目元数据存储在名为dir的structdirent*中。该程序多次访问字段dir->d_name。我想知道设置辅助字符指针(例如char*str=dir->d_name)是否会使程序更快。我知道取消引用指针是一项相对昂贵的操作。问题是,如果我设置了一个辅助变量,我仍然在取消引用一个指针;唯一的区别是在一种情况下我取消引用一个指向结构的指针,而在第二种情况下我取消

c++ - MSVC 无法识别带有模板自动参数的 constexpr 函数

我试图为值列表中的值创建一个索引元查找器。这是代码:#include#includetemplatestructValueTplList;templateconstexprintMetaFindV(intind){//notfoundcasereturn-1;}templateconstexprintMetaFindV(intind=0){ifconstexpr(std::is_same_v){returnNeedleV==V?ind:MetaFindV(ind+1);}else{returnMetaFindV(ind+1);}}//maintemplatestructMetaInde

c++ - C 和 C++ header : Define global struct inside of another struct

我有一些C代码,其中有一些结构如下所示:typedefstructmy_library_a_tmy_library_a_t;typedefstructmy_library_b_tmy_library_b_t;typedefstructmy_library_c_tmy_library_c_t;structmy_library_a_t{structmy_library_b_t{intdata;structmy_library_c_t{intdata;}c;}b;intdata;};这在C++中不起作用,因为在C中structmy_library_b_t定义了一个全局structmy_lib